#ifndef FPLAYER_FFMPEGDECODER_H
#define FPLAYER_FFMPEGDECODER_H

#include "IDecoder.h"

/**
 * author: x-fan
 * date: 2024/1/9
 * desc: FFMpeg的解码器
 */
class FFMpegDecoder : public IDecoder {
protected:
  //解码器上下文
  AVCodecContext *_pCodecCtx = nullptr;
  //解码器上下文的字典
  AVDictionary *_pOptions = nullptr;
  //解码后的一帧数据
  AVFrame *_pFrame = nullptr;

protected:
  /**
   * 查询AVCodec
   * @param decoderParam 解码器参数
   * @return AVCodec
   */
  virtual const AVCodec *findCodec(DecoderParam &decoderParam) = 0;

  /**
   * 初始化编码器的上下文
   * @param pCodecCtx 编码器上下文
   * @param encoderParam 编码器参数
   * @return 0 表示成功
   */
  virtual int32_t initContextParam(AVCodecContext *pCodecCtx, DecoderParam &decoderParam) = 0;

public:
  using IDecoder::IDecoder;

  virtual ~FFMpegDecoder() = default;

  bool initDecoder(DecoderParam &decodeParam) override;

  void releaseDecoder() override;

  bool startDecode(AVPacket *pPacket) override;
};


#endif //FPLAYER_FFMPEGDECODER_H
